package com.ktjy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktjy.mapper.AppInfoMapper;
import com.ktjy.pojo.AppCategory;
import com.ktjy.pojo.AppInfo;
import com.ktjy.pojo.DevUser;
import com.ktjy.service.AppCategoryService;
import com.ktjy.service.AppInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/appInfo")
public class AppInfoController {

    @Autowired
    AppInfoService appInfoService;

    @Autowired
    AppCategoryService appCategoryService;


    /**
     *列表
     * @param session
     * @param pageIndex 当前页码
     * @param querySoftwareName  软件名称
     * @param queryStatus  状态
     * @param queryFlatformId 平台ID
     * @param queryCategoryLevel3  三级分类
     * @param queryCategoryLevel2  二级分类
     * @param queryCategoryLevel1  一级分类
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String applist(HttpSession session,
                          @RequestParam(value = "pageIndex",defaultValue = "1")Integer pageIndex,
                          @RequestParam(value = "querySoftwareName",required = false)String querySoftwareName,
                          @RequestParam(value = "queryStatus",required = false)Integer queryStatus,
                          @RequestParam(value = "queryFlatformId",required = false)Integer queryFlatformId,
                          @RequestParam(value = "queryCategoryLevel3",required = false)Integer queryCategoryLevel3,
                          @RequestParam(value = "queryCategoryLevel2",required = false)Integer queryCategoryLevel2,
                          @RequestParam(value = "queryCategoryLevel1",required = false)Integer queryCategoryLevel1,
                          Model model) {
        //取当前登录用户的id
        DevUser devUser = (DevUser)session.getAttribute("devUserSession");
        Page<AppInfo> page = new Page<>(pageIndex,5);
        Page<AppInfo> appInfoList=appInfoService.selectAll(page,devUser.getId(),
                querySoftwareName,
                queryStatus,
                queryFlatformId,
                queryCategoryLevel1,
                queryCategoryLevel2,
                queryCategoryLevel3  );
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("parentId",1);
        List<AppCategory> appCategories = appCategoryService.selectType(queryWrapper);
        model.addAttribute("categoryLevel1List",appCategories);
        model.addAttribute("appInfoList",appInfoList);
        return "/developer/appinfolist";
    }
}
